// Timer只执行一次，Ticker可以周期的执行
package main

import (
	"fmt"
	"time"
)

func main() {
	ticker := time.NewTicker(time.Second)
	counter := 1
	for _ = range ticker.C {
		fmt.Println("ticker...")
		counter++
		fmt.Println(counter)
		if counter >= 5 {
			break
		}
	}
	ticker.Stop()

	chanIInt := make(chan int)
	ticker1 := time.NewTicker(time.Second)
	go func() {
		for _ = range ticker1.C {
			select {
			case chanIInt <- 1:
			case chanIInt <- 2:
			case chanIInt <- 3:
			}
		}
	}()
	sum := 0
	for v := range chanIInt {
		fmt.Printf("接收:%v\n", v)
		sum += v
		if sum >= 10 {
			fmt.Printf("sum:%v\n", sum)
			break
		}
	}
}
